package com.irdstudio.tdp.console.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.tdp.console.service.facade.OsrvArrangeVarService;
import com.irdstudio.tdp.console.dao.OsrvArrangeVarDao;
import com.irdstudio.tdp.console.dao.domain.OsrvArrangeVar;
import com.irdstudio.tdp.console.service.vo.OsrvArrangeVarVO;
import com.irdstudio.sdk.beans.core.base.FrameworkService;
/**
 * <p>ServiceImpl: 服务编排变量				<p>
 * @author zjj
 * @date 2021-04-01
 */
@Service("osrvArrangeVarServiceImpl")
public class OsrvArrangeVarServiceImpl implements OsrvArrangeVarService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(OsrvArrangeVarServiceImpl.class);

	@Autowired
	private OsrvArrangeVarDao osrvArrangeVarDao;
	
	/**
	 * 新增操作
	 */
	public int insertOsrvArrangeVar(OsrvArrangeVarVO inOsrvArrangeVarVo) {
		logger.debug("当前新增数据为:"+ inOsrvArrangeVarVo.toString());
		int num = 0;
		try {
			OsrvArrangeVar osrvArrangeVar = new OsrvArrangeVar();
			beanCopy(inOsrvArrangeVarVo, osrvArrangeVar);
			num = osrvArrangeVarDao.insertOsrvArrangeVar(osrvArrangeVar);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(OsrvArrangeVarVO inOsrvArrangeVarVo) {
		logger.debug("当前删除数据条件为:"+ inOsrvArrangeVarVo);
		int num = 0;
		try {
			OsrvArrangeVar osrvArrangeVar = new OsrvArrangeVar();
			beanCopy(inOsrvArrangeVarVo, osrvArrangeVar);
			num = osrvArrangeVarDao.deleteByPk(osrvArrangeVar);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inOsrvArrangeVarVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(OsrvArrangeVarVO inOsrvArrangeVarVo) {
		logger.debug("当前修改数据为:"+ inOsrvArrangeVarVo.toString());
		int num = 0;
		try {
			OsrvArrangeVar osrvArrangeVar = new OsrvArrangeVar();
			beanCopy(inOsrvArrangeVarVo, osrvArrangeVar);
			num = osrvArrangeVarDao.updateByPk(osrvArrangeVar);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inOsrvArrangeVarVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public OsrvArrangeVarVO queryByPk(OsrvArrangeVarVO inOsrvArrangeVarVo) {
		
		logger.debug("当前查询参数信息为:"+ inOsrvArrangeVarVo);
		try {
			OsrvArrangeVar queryOsrvArrangeVar = new OsrvArrangeVar();
			beanCopy(inOsrvArrangeVarVo, queryOsrvArrangeVar);
			OsrvArrangeVar queryRslOsrvArrangeVar = osrvArrangeVarDao.queryByPk(queryOsrvArrangeVar);
			if (Objects.nonNull(queryRslOsrvArrangeVar)) {
				OsrvArrangeVarVO outOsrvArrangeVarVo = beanCopy(queryRslOsrvArrangeVar, new OsrvArrangeVarVO());
				logger.debug("当前查询结果为:"+ outOsrvArrangeVarVo.toString());
				return outOsrvArrangeVarVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvArrangeVarVO> queryAllOwnerNoPage(OsrvArrangeVarVO osrvArrangeVarVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<OsrvArrangeVarVO> list = null;
		try {
			List<OsrvArrangeVar> osrvArrangeVars = osrvArrangeVarDao.queryAllOwner(osrvArrangeVarVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ osrvArrangeVars.size());
			pageSet(osrvArrangeVars, osrvArrangeVarVo);
			list = (List<OsrvArrangeVarVO>) beansCopy(osrvArrangeVars, OsrvArrangeVarVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvArrangeVarVO> queryAllOwner(OsrvArrangeVarVO osrvArrangeVarVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<OsrvArrangeVarVO> list = null;
		try {
			List<OsrvArrangeVar> osrvArrangeVars = osrvArrangeVarDao.queryAllOwnerByPage(osrvArrangeVarVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ osrvArrangeVars.size());
			pageSet(osrvArrangeVars, osrvArrangeVarVo);
			list = (List<OsrvArrangeVarVO>) beansCopy(osrvArrangeVars, OsrvArrangeVarVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvArrangeVarVO> queryAllCurrOrg(OsrvArrangeVarVO osrvArrangeVarVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<OsrvArrangeVar> osrvArrangeVars = osrvArrangeVarDao.queryAllCurrOrgByPage(osrvArrangeVarVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+osrvArrangeVars.size());
		List<OsrvArrangeVarVO> list = null;
		try {
			pageSet(osrvArrangeVars, osrvArrangeVarVo);
			list = (List<OsrvArrangeVarVO>) beansCopy(osrvArrangeVars, OsrvArrangeVarVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<OsrvArrangeVarVO> queryAllCurrDownOrg(OsrvArrangeVarVO osrvArrangeVarVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<OsrvArrangeVar> osrvArrangeVars = osrvArrangeVarDao.queryAllCurrDownOrgByPage(osrvArrangeVarVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ osrvArrangeVars.size());
		List<OsrvArrangeVarVO> list = null;
		try {
			pageSet(osrvArrangeVars, osrvArrangeVarVo);
			list = (List<OsrvArrangeVarVO>) beansCopy(osrvArrangeVars, OsrvArrangeVarVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
